package com.mmy.fta.usercenter.service;

import com.mmy.fta.usercenter.entity.ColdTruckEntity;
import com.mmy.fta.usercenter.repository.ColdTruckEntityMapper;
import com.ymm.common.rpc.YmmResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author qingyu.meng
 * @date 2021年11月02日 8:21 下午
 * @Description
 */
@Service
@Slf4j
public class ColdTruckService {
    @Autowired
    ColdTruckEntityMapper coldTruckEntityMapper;

    public YmmResult generateTemperature(){
        for (int i = 0; i < 1000000; i++) {
            double temperature = 20d - Math.random()*(20d - 10d);
            double humidity = 60d - Math.random()*(60d - 40d);
            ColdTruckEntity coldTruckEntity = new ColdTruckEntity();
            coldTruckEntity.setTemperature(temperature);
            coldTruckEntity.setHumidity(humidity);
            coldTruckEntity.setTruckId(2L);
            coldTruckEntityMapper.insertSelective(coldTruckEntity);
            log.info(coldTruckEntity.toString());
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        return YmmResult.succResult();
    }
}
